<template>
  <div>
    <el-form :model="form" label-width="auto" style="max-width: 600px">
      <el-form-item label="菜单名称">
        <el-input v-model="form.menuName" />
      </el-form-item>
      <el-form-item label="父级菜单">
        <el-select v-model="form.pId" placeholder="请选择父级菜单">
          <el-option
            v-for="item in tableData"
            :label="item.menuName"
            :value="item.menuId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="路径">
        <el-input v-model="form.menusUrl" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="addMenu">添加</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from "vue";
import axios from "axios";
import { ElMessage, ElMessageBox } from "element-plus";
import router from "@/router";
import { KongaUrl } from "@/axios/axiosHelp";
const form = reactive({
  menuId: 0,
  menuName: "",
  menusUrl: "",
  pId: "",
  creator: "",
  creationDate: "2025-02-27T07:22:54.402Z",
  updateor: "",
  updatedate: "2025-02-27T07:22:54.402Z",
  menuOrder: 0,
});

const forms = reactive({
  PageIndex: 1,
  PageSize: 500,
  TotalCount: 0,
});
//下拉
const tableData: any = ref([]);
const getMenu = () => {
  KongaUrl({
    url: "/user/api/Backed/GetMenu",
    method: "get",
    params: forms,
  }).then((res) => {
    console.log(res.data.data);
    tableData.value = res.data.data;
  });
};
//添加
const addMenu = () => {
  KongaUrl({
    url: "/userwriter/api/Menu/AddMenu",
    method: "post",
    data: form,
  }).then((res) => {
    if (res.data.code == 200) {
      ElMessage.success(res.data.message);
      router.push("/GetMenu");
    } else {
      ElMessage.error(res.data.message);
    }
  });
};
onMounted(() => {
  getMenu();
});
</script>

<style scoped></style>